Skip to content

Conversation

@empiricompany
Copy link
Contributor

@empiricompany empiricompany commented Nov 27, 2025

Description (*)

This PR fixes a bug where tier prices display incorrect values when a product has a special price that is lower than some tier prices.

The Problem:

When a product has tier prices configured and a special price is set, two different filtering mechanisms are applied:

  1. HTML rendering (Mage_Catalog_Block_Product_Abstract::getTierPrices()): Only tier prices lower than the final price are rendered in HTML. Each rendered tier gets a sequential CSS class (.tier-0, .tier-1, etc.)

  2. JavaScript config (Mage_Catalog_Helper_Product_Type_Composite::prepareJsonProductConfig()): The tierPrices array is built from ALL tier prices (via $product->getTierPrice()), regardless of whether they are greater than the special price.

This causes an index mismatch between the HTML elements and the JavaScript array.

Example:

  • Product with special price: €12
  • Tier 0: €10 for 5 units (shown as .tier-0 in HTML)
  • Tier 1: €15 for 10 units (NOT shown - greater than special price)
  • Tier 2: €8 for 20 units (shown as .tier-1 in HTML)

The JavaScript tierPrices array contains 3 elements [diff0, diff1, diff2], but HTML only has 2 elements with classes .tier-0 and .tier-1.

When the JS tries to update .tier-1 using tierPrices[1], it applies the wrong tier price difference (from the hidden tier instead of the third tier).

The Fix:

Added filtering in prepareJsonProductConfig() to skip tier prices that are greater than or equal to the final price, maintaining consistency with the HTML filtering logic.

Related Pull Requests

  • N/A

Fixed Issues (if relevant)

  • N/A (discovered during development)

Manual testing scenarios (*)

  1. Create a simple product with base price €20
  2. Add tier prices: €15 for qty 5, €18 for qty 10, €10 for qty 20
  3. Set special price €16
  4. Go to product page in frontend
  5. Before fix: The tier price for qty 20 shows incorrect price (uses the difference from the hidden €18 tier)
  6. After fix: The tier price for qty 20 shows correct price €10

Questions or comments

The same filtering logic from Mage_Catalog_Block_Product_Abstract::getTierPrices() (line 416) is now applied in the helper to ensure the JS array indices match the rendered HTML elements.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)

Added a check to skip tier prices that are greater than or equal to the final price.
Copilot AI review requested due to automatic review settings November 27, 2025 12:26
@github-actions github-actions bot added the Component: Catalog Relates to Mage_Catalog label Nov 27, 2025
Copilot finished reviewing on behalf of empiricompany November 27, 2025 12:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a tier price display bug where incorrect tier prices are shown when some tier prices are higher than a product's special price. The root cause is an index mismatch between HTML-rendered tier price elements and the JavaScript tier price array used for dynamic price updates.

Key Changes:

  • Added filtering logic to skip tier prices that are greater than or equal to the final price in the JavaScript configuration
  • Ensures the JavaScript tierPrices array indices align with the CSS class indices (.tier-0, .tier-1, etc.) of the rendered HTML elements

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 27, 2025

Test Results

914 tests  ±0   903 ✅ ±0   15s ⏱️ ±0s
201 suites ±0    11 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 58fb632. ± Comparison against base commit 3e6c4e3.

♻️ This comment has been updated with latest results.

@sreichel
Copy link
Contributor

sreichel commented Dec 1, 2025

Thanks.

@sreichel sreichel added the bug label Dec 1, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 3, 2025

@sreichel
Copy link
Contributor

sreichel commented Dec 3, 2025

Tested. Merged.

Thanks @empiricompany.

@sreichel sreichel merged commit 8f3f6a0 into main Dec 3, 2025
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Component: Catalog Relates to Mage_Catalog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants